package xyf.p10.dp;

/**
 * ClassName: J046_TranslateNum
 * Description:
 * Author: xyf
 * Date: 9/9/22 10:29 AM
 * Version: 1.0
 **/
public class J046_TranslateNum
{
    public int translateNum(int num)
    {
        String numStr = String.valueOf(num);

        if (numStr.length() <= 1)
        {
            return 1;
        }

        int[] dp = new int[numStr.length()];

        dp[0] = 1;

        for (int i = 1; i < numStr.length(); i++)
        {
            dp[i] += dp[i - 1];

            if ((numStr.charAt(i - 1) == '1')
                    || (numStr.charAt(i - 1) == '2' && numStr.charAt(i) < '6' && numStr.charAt(i) >= '0'))
            {
                if (i != 1)
                {
                    dp[i] += dp[i - 2];
                }
                else
                {
                    dp[i] += 1;
                }
            }
        }

        return dp[numStr.length() - 1];
    }
}